﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DbView.aspx.cs" Inherits="Yule8xWechat.DbView" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <style type="text/css">
        body, td {
            font-size: 13px;
        }

        a {
            text-decoration: none;
        }
    </style>
</head>
<body>
    <%
        if (action == "login")
        {
    %>
    <form method="post" action="DbView.aspx">
        <table>
            <tr>
                <th>用户名：</th>
                <td>
                    <input type="text" name="username" /></td>
            </tr>
            <tr>
                <th>密码：</th>
                <td>
                    <input type="password" name="password" /></td>
            </tr>
        </table>
        <input type="hidden" name="action" value="dologin" />
        <button type="submit">立即登录</button>
    </form>
    <%
            Response.End();
        } %>
    <table style="width: 100%">
        <tr>
            <td>
                <a href="?action=clearall" onclick="return confirm('您确定要清空整个数据库吗?')">[一键清空数据库]</a> |
                <a href="?action=showdata">[查看整个数据库数据]</a><br />
                <a href="?table=TUserProperty&con=bozhong">[泊众房卡]</a> |
                <a href="?table=UserCurrencyInfo&con=wanghu">[网狐游戏豆]</a><br />
                <div style="max-height: 240px; overflow: auto;">
                    <%

                        string[] skiptables = new string[] { "t_area" }; // 忽略的表
                        if (null != dtTables)
                        {
                            string tabletmp;
                            foreach (System.Data.DataRow r in dtTables.Rows)
                            {
                                tabletmp = r["Name"].ToString();
                                if (skiptables.Length > 0 && skiptables.Contains(tabletmp))
                                {
                                    continue;
                                }
                                Response.Write(string.Format("<a href='?table={0}&limit=50'>{0}</a>", tabletmp));
                                Response.Write(string.Format("<a href='?table={0}&limit=50&simple=yes' title='精简查询'>[s]</a>", tabletmp));
                                Response.Write(string.Format(" <a href='?table={0}&action=clear' onclick='return confirm(\"您确定要清空数据表{0}吗?\");'>[清空]</a><br />", tabletmp));
                            }
                        }
                    %>
                </div>
            </td>
            <td>
                <div>
                    :: <%=table %><br />
                    <form method="post" action="DbView.aspx?table=<%=table %>">
                        <textarea name="sql" cols="150" rows="12"><%=sql %></textarea><br />
                        <input type="hidden" name="con" value="<%=con %>" />
                        <button type="submit">运行</button>
                    </form>
                </div>
            </td>
        </tr>
    </table>
    <div>
        <%
            int icol = 0;
            IList<string> cols;
            if (count > -1)
            {
                Response.Write("受影响行数：" + count);
            }
            if ("showdata" == action)
            {
                string[] hidetables = new string[] { "t_user_captcha", "t_log_login", "t_game_manufacturer", "t_game_currency", "t_area" };
                foreach (System.Data.DataRow r in dtTables.Rows)
                {
                    table = r["Name"].ToString();
                    if (hidetables.Contains(table))
                    {
                        continue;
                    }
                    dtList = QueryTable(table);

                    cols = new List<string>();
                    Response.Write("<div style='max-width:99%; max-height:300px; min-height:50px; overflow:auto'>" + table + "<table border='1'>");
                    Response.Write("<tr>");
                    foreach (System.Data.DataColumn c in dtList.Columns)
                    {
                        Response.Write(string.Format("<th>{0}</th>", c.ColumnName));
                        cols.Add(c.ColumnName);
                    }
                    Response.Write("</tr>");
                    object[] cells;
                    foreach (System.Data.DataRow r2 in dtList.Rows)
                    {
                        cells = r2.ItemArray;
                        Response.Write("<tr onclick='this.style.backgroundColor=\"#efefef\"'>");
                        icol = 0;
                        foreach (object cell in cells)
                        {
                            Response.Write(string.Format("<td title='{1}'>{0}</td>", cell, cols[icol]));
                            icol++;
                        }
                        Response.Write("</tr>");
                    }
                    Response.Write("</table></div>");
                }
                dtList = null;

            }
            if (null != dtList)
            {
                cols = new List<string>();
                Response.Write("<div style='max-width:99%; max-height:600px; min-height:300px; overflow:auto'><table border='1'>");
                Response.Write("<tr>");
                foreach (System.Data.DataColumn c in dtList.Columns)
                {
                    Response.Write(string.Format("<th>{0}</th>", c.ColumnName));
                    cols.Add(c.ColumnName);
                }
                Response.Write("</tr>");
                object[] cells;
                foreach (System.Data.DataRow r in dtList.Rows)
                {
                    cells = r.ItemArray;
                    Response.Write("<tr onclick='this.style.backgroundColor=\"#efefef\"'>");
                    icol = 0;
                    foreach (object cell in cells)
                    {
                        Response.Write(string.Format("<td title='{1}'>{0}</td>", cell, cols[icol]));
                        icol++;
                    }
                    Response.Write("</tr>");
                }
                Response.Write("</table></div>");
            }
        %>
    </div>
</body>
</html>
